home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3602 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help in C
  5. Date: 24 Jan 1996 17:52:30 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4e5rku$9jo@clarknet.clark.net>
  8. References: <4e4h29$3f2@cville-srv.wam.umd.edu>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. David Leung (leungyl@wam.umd.edu) wrote:
  16. : I am studying C/C++ and I arrived at a problem that I am stuck with.
  17. : I think it is easy for expericenced programmers, if you can help me
  18. : please email me at leungyl@wam.umd.edu
  19. : this is the problem
  20. : input a five digit number
  21. : then, separate the five digits into 5 separate numbers and evaluate them
  22. : independently. Basically, cut the number into five pieces. This is what
  23. : I wrote.....
  24. : cout <<  "Enter a five digit number: ";
  25. : cin >> input;
  26. : digi1 = input / 10000;
  27. : digi2 = input / 1000 - digi1 * 10;
  28. : digi3 = input / 100 - digi1 * 100 - digi2 * 10;
  29. : digi4 = input / 10 - digi1 * 1000 - digi2 * 100 - digi3 * 10;
  30. : digi5 = input - digi1 * 10000 - digi2 * 1000 - digi3 * 100 - digi4 * 10;
  31. : cout << input << endl;
  32. : cout << digi1 << endl;
  33. : cout << digi2 << endl;
  34. : cout << digi3 << endl;
  35. : cout << digi4 << endl;
  36. : cout << digi5 << endl;
  37. : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  38. : the problem is, it work for some numbers, but for others it doesn't work.
  39. : Why? Can somebody help me??Thanks very much.
  40.  
  41. "It doesn't work" isn't much of a clue! What do you mean by "it doesn't 
  42. work"? What does happen? What numbers does it work for, and what numbers 
  43. doesn't it work for?
  44.  
  45. Also, how do you have input, dig1, etc., declared?
  46.